#include "defvar.h"

extern	void	Get_Sensor(void);

void StepMotorExec( short ReqCount , U8 Motion , U8 Speed , U8 motor );

#define	SEAL_HOME_MOVE_LEN	2160
#define	SEAL_MOVE_LEN		2160
#define	PF_MAX_LENGTH		(2160 * 4)
#define	PF_NEAR_END_LEN		(120)
#define	PF_TRY_LOAD_LEN	1080
#define	FD_COUNTER	6

#define	PPS_NSPD	(F8CLKM / 1180 / 4)						/* Normal Speed */
#define	PPS_SSPD	(F8CLKM / 680 / 4)
//#define	PPS_FXSPD	PPS1800
#define	PFMACCSTR	(F8CLKM / 200 / 4)	//400 PPS startup
#define 	PFMBRKEND	(F8CLKM / 200 / 4)	//400 PPS Stop
#define STEPMOTORPOWERON	(F8CLKM / 200 / 4)		//1ms
#define	STEPMOTORPOWEROFF	(F8CLKM / 200)

#define PFMACCELSTEPS	40
#define PFMBRAKESTEPS	40

#define	PFASTEP00  100	/* STEP  0 */
#define	PFASTEP01   85	/* STEP  1 */
#define	PFASTEP02   75	/* STEP  2 */
#define	PFASTEP03   66	/* STEP  3 */
#define	PFASTEP04   58	/* STEP  4 */
#define	PFASTEP05   51	/* STEP  5 */
#define	PFASTEP06   45	/* STEP  6 */
#define	PFASTEP07   40	/* STEP  7 */
#define	PFASTEP08   35	/* STEP  8 */
#define	PFASTEP09   31	/* STEP  9 */
#define	PFASTEP10   28	/* STEP 10 */
#define	PFASTEP11   25	/* STEP 11 */
#define	PFASTEP12   22	/* STEP 12 */
#define	PFASTEP13   20	/* STEP 13 */
#define	PFASTEP14   17	/* STEP 14 */
#define	PFASTEP15   15	/* STEP 15 */
#define	PFASTEP16   13	/* STEP 16 */
#define	PFASTEP17   11	/* STEP 17 */
#define	PFASTEP18   10	/* STEP 18 */
#define	PFASTEP19    9	/* STEP 19 */
#define	PFASTEP20    8	/* STEP 20 */
#define	PFASTEP21    7	/* STEP 21 */
#define	PFASTEP22    6	/* STEP 22 */
#define	PFASTEP23    5	/* STEP 23 */
#define	PFASTEP24    5	/* STEP 24 */
#define	PFASTEP25    4	/* STEP 25 */
#define	PFASTEP26    4	/* STEP 26 */
#define	PFASTEP27    3	/* STEP 27 */
#define	PFASTEP28    3	/* STEP 28 */
#define	PFASTEP29    3	/* STEP 29 */
#define	PFASTEP30    2	/* STEP 30 */
#define	PFASTEP31    2	/* STEP 31 */
#define	PFASTEP32    2	/* STEP 32 */
#define	PFASTEP33    2	/* STEP 33 */
#define	PFASTEP34    2	/* STEP 34 */
#define	PFASTEP35    1	/* STEP 35 */
#define	PFASTEP36    1	/* STEP 36 */
#define	PFASTEP37    1	/* STEP 37 */
#define	PFASTEP38    1	/* STEP 38 */
#define	PFASTEP39    0	/* STEP 39 */

#define	PFASTEPBS	100	/* BASE   */

#define	PFACCEL40STEP( PPS_SPD )	\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP00+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP01+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP02+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP03+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP04+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP05+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP06+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP07+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP08+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP09+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP10+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP11+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP12+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)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R-PPS_SPD)/PFASTEPBS*PFASTEP35+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP36+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP37+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP38+PPS_SPD,\
	(PFMACCSTR-PPS_SPD)/PFASTEPBS*PFASTEP39+PPS_SPD,

const U16	PfmAccelTbl[2][PFMACCELSTEPS + 2] =
{
{
	PFMACCELSTEPS,
	PFACCEL40STEP(PPS_SSPD)
	0
},
{
	PFMACCELSTEPS,
	PFACCEL40STEP(PPS_NSPD)
	0
}
};

#define	PFBSTEP00    0		/* STEP  0 */
#define	PFBSTEP01    0		/* STEP  1 */
#define	PFBSTEP02    1		/* STEP  2 */
#define	PFBSTEP03    1		/* STEP  3 */
#define	PFBSTEP04    1		/* STEP  4 */
#define	PFBSTEP05    1		/* STEP  5 */
#define	PFBSTEP06    2		/* STEP  6 */
#define	PFBSTEP07    2		/* STEP  7 */
#define	PFBSTEP08    2		/* STEP  8 */
#define	PFBSTEP09    2		/* STEP  9 */
#define	PFBSTEP10    3		/* STEP 10 */
#define	PFBSTEP11    3		/* STEP 11 */
#define	PFBSTEP12    3		/* STEP 12 */
#define	PFBSTEP13    4		/* STEP 13 */
#define	PFBSTEP14    4		/* STEP 14 */
#define	PFBSTEP15    5		/* STEP 15 */
#define	PFBSTEP16    5		/* STEP 16 */
#define	PFBSTEP17    6		/* STEP 17 */
#define	PFBSTEP18    7		/* STEP 18 */
#define	PFBSTEP19    8		/* STEP 19 */
#define	PFBSTEP20    9		/* STEP 20 */
#define	PFBSTEP21   10		/* STEP 21 */
#define	PFBSTEP22   11		/* STEP 22 */
#define	PFBSTEP23   13		/* STEP 23 */
#define	PFBSTEP24   15		/* STEP 24 */
#define	PFBSTEP25   17		/* STEP 25 */
#define	PFBSTEP26   20		/* STEP 26 */
#define	PFBSTEP27   22		/* STEP 27 */
#define	PFBSTEP28   25		/* STEP 28 */
#define	PFBSTEP29   28		/* STEP 29 */
#define	PFBSTEP30   31		/* STEP 30 */
#define	PFBSTEP31   35		/* STEP 31 */
#define	PFBSTEP32   40		/* STEP 32 */
#define	PFBSTEP33   45		/* STEP 33 */
#define	PFBSTEP34   51		/* STEP 34 */
#define	PFBSTEP35   58		/* STEP 35 */
#define	PFBSTEP36   66		/* STEP 36 */
#define	PFBSTEP37   75		/* STEP 37 */
#define	PFBSTEP38   85		/* STEP 38 */
#define	PFBSTEP39  100		/* STEP 39 */
#define	PFBSTEPBS	100	/* BASE   */

#define	PFBRAKE40STEP( PPS_SPD )	\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP00+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP01+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP02+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP03+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP04+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP05+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP06+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP07+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP08+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP09+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP10+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP11+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP12+PPS_SPD,\
	(PFMBRKEND-PPS_SPD)/PFBSTEPBS*PFBSTEP13+PPS_SPD,\
	(PFM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